#include<bits/stdc++.h>
using namespace std;
int T,n,a[200010],sum;
int main(){
freopen("color.in","r",stdin);
freopen("color.out","w",stdout);
ios::sync_with_stdio(false);
cin>>T;
for(int i=1;i<=T;i++){
    sum=0;
    cin>>n;
    for(int j=1;j<=n;j++){
        cin>>a[j];
    }

    for(int j=1;j<=n;j++){
        int s=j;
        while(a[j]==a[j+1]){
            j++;
        }
        sum+=(j-s+1)/2*a[s];
    }
    cout<<sum<<endl;

}

return 0;
}
